package cst.neu.yuejian_31.model;

import java.util.List;

import cst.neu.yuejian_31.bean.VideoBean;
import cst.neu.yuejian_31.iface.VideoIface;
import cst.neu.yuejian_31.iface.VideoListener;
import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.service.VideoService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xxe on 2017/11/1.
 */

public class VideoModel implements VideoIface {
    private Retrofit retrofit;
    public VideoModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void clubVideo(String clubId, final VideoListener videoListener) {
        VideoService videoService=retrofit.create(VideoService.class);
        Call<List<VideoBean>>call=
                videoService.clubVideo(clubId);
        call.enqueue(new Callback<List<VideoBean>>() {
            @Override
            public void onResponse(Call<List<VideoBean>> call, Response<List<VideoBean>> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    videoListener.onSuccess(response.body());
                }else {
                    videoListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<List<VideoBean>> call, Throwable t) {
                videoListener.onFail(t.toString());
            }
        });

    }
}
